package shuzi.update;

import shuzi.data.Database;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

import com.shuzi.offer.R;

public class UpdateManager {

	/**
	 * 获取当前版本
	 * 
	 * @param context
	 * @return
	 */
	public int getVerCode(Context context) {
		int verCode = -1;
		try {
			String pageName = context.getPackageName();
			PackageInfo packageInfo = context.getPackageManager()
					.getPackageInfo(pageName, 0);
			verCode = packageInfo.versionCode;
		} catch (NameNotFoundException e) {
			Log.e(Database.TAG, e.getMessage());
		}
		return verCode;
	}

	/**
	 * 获取版本名称
	 * 
	 * @param context
	 * @return
	 */
	public String getVerName(Context context) {
		String verName = "";
		try {
			String pageName = context.getPackageName();
			PackageInfo packageInfo = context.getPackageManager()
					.getPackageInfo(pageName, 0);
			verName = packageInfo.versionName;
		} catch (NameNotFoundException e) {
			Log.e(Database.TAG, e.getMessage());
		}
		return verName;
	}

	/**
	 * 获取应用 名称
	 * 
	 * @param context
	 * @return
	 */
	public String getAppName(Context context) {
		String appName = context.getResources().getText(R.string.app_name)
				.toString();
		return appName;
	}
	
	
}
